/*
* Copyright (C) 2012-2014 qar
* License: http://www.gnu.org/licenses/gpl.html GPL version 2
*/

#ifndef AUTHENTICATOR_H
#define AUTHENTICATOR_H

#include <QtCore>

class Signer;

class Authenticator
{
public:
    enum AuthenticationAlgorithm {
        NoAuthentication = 0
    };

    Authenticator(AuthenticationAlgorithm algorithm, QString keyFile);
    virtual ~Authenticator();

    void setAlgorithm(AuthenticationAlgorithm algorithm, QString keyFile);
    AuthenticationAlgorithm getAlgorithm() const;
    QString getAlgorithmName() const;

    qint64 hashSize() const;

    // The length of the data must be a multiple of the block size.
    void signSegment(const QByteArray &segment, QByteArray &signedSegment);
    bool checkAndExtractSegment(const QByteArray &signedSegment, QByteArray &segment);

    // Serialization of parameters
    bool toStream(QDataStream &s);
    bool fromStream(QDataStream &s);

protected:
    AuthenticationAlgorithm algorithm;
    QString keyFile;
    Signer *signer;

private:
    Q_DISABLE_COPY(Authenticator)
};

#endif // AUTHENTICATOR_H
